import Pluto,struct,codecs,fnmatch
fl=Pluto.walk('UI')
for fn in fl:
        if fnmatch.fnmatch(fn,'*.txt'):
                continue
        fp=open(fn,'rb')
        if fp.read(4)!='\x08\x00\x00\x00':
                continue
        print fn
        fp.seek(0)
        size=len(fp.read())
        i=8
        tar=codecs.open(fn+'.txt','wb','utf_16')
        while i<size:
                fp.seek(i)
                lenght=struct.unpack('i',fp.read(4))[0]
                text=[]
                for j in range(0,lenght-4,2):
                        value=struct.unpack('H',fp.read(2))[0]
                        if value==0:
                                break
                        if value==0xa:
                                word='\r\n'
                        else:
                                word=unichr(value)
                        text.append(word)
                tar.write('//start\r\n'+''.join(text)+'\r\n//end\r\n\r\n')
                i+=lenght
        fp.close()
        tar.close()